//
//  SpecailAudioHeaderView.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/12/29.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "SpecailAudioHeaderView.h"

@interface SpecailAudioHeaderView ()

@property (nonatomic, strong)UIButton * defultBtn;

@property (nonatomic, strong)UIButton * lastBtn;

@property (nonatomic, strong)UIButton * downloadAllBtn;
@end

@implementation SpecailAudioHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setup];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
    
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setup];
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    [self setup];
    self.contentView.backgroundColor = [UIColor whiteColor];
}

- (void)setup {
    
    self.defultBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self.contentView addSubview:self.defultBtn];
    self.defultBtn.titleLabel.numberOfLines = 0;
    @weakify(self);
    [self.defultBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.leading.equalTo(self.contentView.mas_leading).offset(10);
        make.top.equalTo(self.contentView.mas_top);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.width.mas_equalTo(100);
    }];
    self.defultBtn.contentMode = UIViewContentModeLeft;
    self.defultBtn.tag = 100;
    self.defultBtn.titleLabel.font = Font(14);
    [self.defultBtn setTitle:MYLocalizedString(@"PUBLIC_SORT_DEFAULT", nil) forState:UIControlStateNormal];
    [self.defultBtn setTitleColor:kContentColor forState:UIControlStateNormal];
    [self.defultBtn setTitleColor:kThemeColor forState:UIControlStateSelected];
    [self.defultBtn addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.lastBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.lastBtn.tag = 101;
    [self.contentView addSubview:self.lastBtn];
    self.lastBtn.contentMode = UIViewContentModeLeft;
    self.lastBtn.titleLabel.numberOfLines = 0;
    [self.lastBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.leading.equalTo(self.defultBtn.mas_trailing).offset(16);
        make.top.equalTo(self.contentView.mas_top);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.width.mas_equalTo(100);
    }];
    self.lastBtn.titleLabel.font = Font(14);
    [self.lastBtn setTitle:MYLocalizedString(@"PUBLIC_SORT_UPDATE", nil) forState:UIControlStateNormal];
    [self.lastBtn setTitleColor:kContentColor forState:UIControlStateNormal];
    [self.lastBtn setTitleColor:kThemeColor forState:UIControlStateSelected];
    [self.lastBtn addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.downloadAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.downloadAllBtn.tag = 102;
    [self.contentView addSubview:self.downloadAllBtn];
    [self.downloadAllBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        @strongify(self);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-10);
        make.top.equalTo(self.contentView.mas_top);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.width.mas_equalTo(100);
    }];
    
    self.downloadAllBtn.titleLabel.textAlignment = NSTextAlignmentRight;
    self.downloadAllBtn.contentMode = UIViewContentModeRight;
    self.downloadAllBtn.titleLabel.font = Font(14);
    [self.downloadAllBtn setTitle:MYLocalizedString(@"PUBLIC_DOWNLOAD_ALL", nil) forState:UIControlStateNormal];
    [self.downloadAllBtn setTitleColor:kContentColor forState:UIControlStateNormal];
    [self.downloadAllBtn setTitleColor:kThemeColor forState:UIControlStateSelected];
    [self.downloadAllBtn addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)setSortType:(NSInteger)sortType {
    
    if (sortType == 0) {
        
        self.defultBtn.selected = YES;
        self.lastBtn.selected = NO;
    } else {
        
        self.defultBtn.selected = NO;
        self.lastBtn.selected = YES;
    }
}

- (void)tapAction:(UIButton *)sender {
    
    AudioHeaderNum type = default_Sequence;
    
    switch (sender.tag) {
        case 100:
        {
            type = default_Sequence;
        }
            break;
        case 101:
        {
            type = last_Sequence;
        }
            break;
        case 102:
        {
            type = download_All;
        }
            break;
        default:
            break;
    }
    
    if (_delegate && [_delegate respondsToSelector:@selector(SpecailAudioHeaderTapAction:)]) {
        
        [_delegate SpecailAudioHeaderTapAction:type];
    }
}
@end

